package com.xbongbong.pro.statistic.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author zcp
 * @version v1.0
 * @since v1.0
 */
@Getter
public enum ChartOperateEnum {
    /**
     * 图表的按钮alias值    ○
     *     ■穿透、钻取：柱形图、折线图、面积图、饼图、横向柱形图、气泡图、数据统计表
     *     ■只有钻取：地图     地图本身就是一种钻取，无需钻取设置
     *     ■无穿透、无钻取的：指标图、副指标、查询表
     *     ■只有穿透：雷达图、双轴图、漏斗图
     */
    //穿透
    THROUGH(1, "through", ChartTypeEnum.supportThroughChartType(), "enum.proPermissionAlias.memo.chart_through"),
    //钻取
    DRILL(2, "drill", ChartTypeEnum.supportDrillChartType(), "enum.proPermissionAlias.memo.chart_drill"),
    //联动
    LINKAGE(3, "linkage", ChartTypeEnum.supportLinkageChartType(), "enum.proPermissionAlias.memo.chart_linkage"),
    ;
    private int code;
    private String alias;
    /**
     * 拥有钻取交互的默认图表类型（注：只是有图表交互的图表类型，不是说就有钻取设置，比如地图就无钻取设置，但是它的交互属于钻取）
     */
    private List<Integer> defaultChartTypeList;

    private String memo;

    ChartOperateEnum(int code, String alias, List<Integer> defaultChartTypeList, String memo) {
        this.code = code;
        this.alias = alias;
        this.defaultChartTypeList = defaultChartTypeList;
        this.memo = memo;
    }

    /**
     * 通过alias获取枚举
     * @param alias
     * @return com.xbongbong.pro.statistic.enums.ChartOperateEnum
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static ChartOperateEnum getByAlias(String alias) {
        for (ChartOperateEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return null;
    }

    /**
     * 需要保持互斥关系的按钮
     *
     * @param operateEnum
     * @return boolean
     * @author zyy
     * @date 2022/12/9
     * @version v1.0
     */
    public static boolean mutexType(ChartOperateEnum operateEnum) {
        if(Objects.isNull(operateEnum)){
            return false;
        }
        return Arrays.asList(DRILL,LINKAGE).contains(operateEnum);
    }

    public static boolean mutexTypeByAlisa(String opKey) {
        return mutexType(getByAlias(opKey));
    }

    public String getMemo() {
        return I18nMessageUtil.getMessage(memo);
    }

}
